#pragma once

#include "stdafx.h"
#include "items.h"

using namespace std;

class ItemScene;
class virtualConnector;
class Vertex;
class Title;

class SceneView : public QGraphicsScene
{
	Q_OBJECT

public:
	SceneView(QWeakPointer<Common> _common);
	~SceneView();
	vector<QSharedPointer<ItemScene>> list_of_items;
	vector<QSharedPointer<Connector>> list_of_connectors;
	void addVirtualConnector(QWeakPointer<ConnectionPoint> _point);
	QWeakPointer<Common> common;
	QSharedPointer<ItemScene> addItemToScene(const QPointF &_pos, const ItemScene::itemType_t &_type, const QString &_name = "", const bool &_visibleTitle = true);
	QSharedPointer<Connector> addConnectorToScene(QWeakPointer<ConnectionPoint> _source, QWeakPointer<ConnectionPoint> _dest, const QString &_coordinates = "", const QPointF &_spot_pos = QPointF());
	QSharedPointer<ItemScene> findItemByName(const QString &_name);
	QSharedPointer<Connector> findConnectorByName(const QString &_name);
	int getIndexInList(ItemScene *item);
	void eraseItemFromList(QWeakPointer<ItemScene> item);
	void eraseConnectorFromList(QWeakPointer<Connector> connector);
private:
	bool redraw_virtual_connector;
	ItemScene::itemType_t dropped_item;
	QSharedPointer<ItemScene> virtual_item;
	QSharedPointer<virtualConnector> virtual_connector;
	void cutConnector(int index, QWeakPointer<ConnectionPoint> point);
	void DeleteSelectedItem();
	bool findInnerNodeNearMouse(const QPointF &_pos);
	
public slots:
	void indexDroppedItemChanged(int index){ dropped_item = (ItemScene::itemType_t)index; }
protected:
	void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
	void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
	void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
	void keyPressEvent(QKeyEvent *event);
	void keyReleaseEvent(QKeyEvent *event);
	void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
	void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
	void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
	void dropEvent(QGraphicsSceneDragDropEvent *event);
};
